package com.fzu.thirdpartyservice.controller;

import com.fzu.commonutil.util.R;
import com.fzu.thirdpartyservice.util.FileUtil;
import com.fzu.thirdpartyservice.util.MapUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author zyq
 * @Description 地图控制器
 * @Version 1.0
 **/
@RestController
@RequiredArgsConstructor
public class MapController {

    private final MapUtil mapUtil;

    /**
     * 地址信息转经纬度
     * @param address
     * @return Coordinate
     */
    @GetMapping("/coordinate")
    public R getCoordinate(@RequestParam String address) {
        return R.ok().data(mapUtil.getCoordinate(address));
    }

    /**
     * 经纬度转地址信息
     * @param lng 经度
     * @param lat 纬度
     * @return AddressComponent
     */
    @GetMapping("/address")
    public R getAddress(@RequestParam Double lng, @RequestParam Double lat) {
        return R.ok().data(mapUtil.getAddress(lng, lat));
    }

    /**
     * 计算两个经纬度之间的距离
     * @param startLng
     * @param startLat
     * @param endLng
     * @param endLat
     * @return
     */
    @GetMapping("/distance")
    public R distance(@RequestParam Double startLng, @RequestParam Double startLat,
                      @RequestParam Double endLng, @RequestParam Double endLat) {
        return R.ok().data(mapUtil.getDistance(startLng, startLat, endLng, endLat));
    }
}
